#ifndef BW_FILE_TOOL_H_
#define BW_FILE_TOOL_H_

#include <iostream>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>

#include <sys/types.h>
#include <sys/stat.h>

//#include "upg_define.h"
//#include "upg_comm.h"
#include "bw_public.h"
#include "../../hiapp/inc/enc_type.h"

using namespace std;

namespace bwcgi
{

static std::string uselessStr;

#ifndef MAX_PATH
#define MAX_PATH	SZ_256B
#endif
#ifndef CMD_LEN
#define CMD_LEN		SZ_1K
#endif

/*	解密错误时会报错的信息	*/
#define ENCRYPT_TAG		"bad decrypt"
#define ERROR_READING	"error reading"
#define NO_SUCH_FILE	"No such file or directory"

#define FILEBUFFER_LENGTH 1024
#define EMPTY_STR ""

#define TAR_PRESS			"tar czvf"
#define TAR_UNPRESS			"tar xzvf"
#define ZIP					"zip"
#define UNZIP				"unzip"

#define TAR_TEMP_FILEPATH		"/home/bwsc/upgrade/tar/tmp/"

//typedef struct _st_path_
//{
//    char dir[MAX_PATH];
//    char file[MAX_PATH];
//}PATH;


class Upg_File{
public:
	Upg_File(){}
	~Upg_File(){}

public:
	static bool checkMd5Value(string Md5Str, string filename);
	static bool checkMd5Value(const char * Md5Str, const char * filename);
	static string getMd5Value(string filename);
	static bool getMd5Value(const char * filename, char * Md5Buf, S32 bufLen);

	static bool unZipFile(const char * fileName, const char * filePath, vector<string> * pCheckFile = NULL);
	static bool tarFile(const char * fileName, const char * outFileName);
	static bool unTarFile(const char * fileName, const char * filePath, vector<string> * pCheckFile = NULL);
	
	static bool deleteFile(const char * fileName);
	static bool deleteAllFileInPath(const char * filePath, const char * exceptFile = NULL);
	static bool copyFile(const char * fileName, const char * destPath);
	static bool copyAllFileInPath(const char * srcPath, const char * destPath);
	static bool getAllFileInPath(const char * filePath, vector<string> &fileNames);
		
	static bool checkAndCreatePath(const char * filePath);
	static bool File_Shell_exec(const char* cmdline, char* out, size_t out_len);
	static bool File_UnEncrypt(const char *infile,const char *outfile,const char *password);
    static bool bw_comm_Encrypt(const char *infile,const char *outfile,const char *password);

	static bool File_isPath(const char * filePath);
	static bool File_isExcecutable(const char* fileName);
	static bool File_becomeExcecutable(const char* fileName);
	static bool File_exists(const char* fileName);
	static S32 File_size(const char* fileName);
	static bool File_nameChange(const char* srcFileName, const char *changeName, bool isForced);
	static bool File_move(const char* srcFileName, const char *dstFilePath, bool isForced = true);
	static bool writePipe(const char * content, int len, const char * pipeName);
	static void getPid(string & str, vector<U32> &pid);
	static bool progressIsRun(const char * progressName, std::string & progressInfo = uselessStr, const char * param = nullptr);
	static bool stopProgress(const char *progressName, vector<string> * pParam = NULL);
	static bool startProgress(const char *progressName, const char *Param = nullptr);

	static bool isBigEndian();
};



}/*	namespace	*/
#endif /* BW_INC_H_ */
